package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReportService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

/**
 * 数据统计
 */

@RequestMapping("/admin/report")
@RestController
@Slf4j
@Api(tags = "数据统计")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, //指定格式映射
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        log.info("营业额统计：{}，{}",begin,end);
        TurnoverReportVO turnoverStatistics =  reportService.getTurnoverStatistics(begin,end);
        return Result.success(turnoverStatistics);
    }

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, //指定格式映射
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        log.info("用户统计：{}，{}",begin,end);
        UserReportVO userReportVO = reportService.getUserStatistics(begin,end);
         return Result.success(userReportVO);
    }


    /**
     * 销量前十统计
     * @return
     */
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> salesTop10Statistics(
                  @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, //指定格式映射
                  @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        log.info("销量前十统计：{}，{}",begin,end);
        SalesTop10ReportVO salesTop10ReportVO = reportService.getSalesTop10(begin,end);
        return Result.success(salesTop10ReportVO);
    }


    /**
     * 导出excel报表
     * @param response
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response)
    {
        log.info("到处数据报表");
        reportService.exportBussinessDate(response);
    }

}
